/**
 * 
 */
package com.sogeti.mentormatch.dao.hibernate;

import java.io.Serializable;

import com.sogeti.mentormatch.dao.DataAccessObject;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A simple generic Abstract Data Access Object that all simple DAO's should
 * extend.
 * 
 * @author Matthew L. Maurer <maurer.it@gmail.com>
 */
public class GenericSpringHibernateDAO<DOBJECT, PKEY extends Serializable> extends
        HibernateDaoSupport implements DataAccessObject<DOBJECT, PKEY>
{
    Class<DOBJECT>  clazz;

    /**
     * 
     */
    public GenericSpringHibernateDAO ( Class<DOBJECT> clazz ) {
        this.clazz = clazz;
    }

    @SuppressWarnings ( "unchecked" )
    public PKEY create ( DOBJECT newInstance ) {
        return ( PKEY ) getHibernateTemplate().save(newInstance);
    }

    public void update ( DOBJECT transientObject ) {
        getHibernateTemplate().update(transientObject);
    }

    public void delete ( DOBJECT persistentInstance ) {
        getHibernateTemplate().delete(persistentInstance);
    }

    @SuppressWarnings ( "unchecked" )
    public DOBJECT read ( PKEY id ) {
        return ( DOBJECT ) getHibernateTemplate().get(clazz, id);
    }
}
